package zgame.config.loader;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import zgame.main.Global;

public class ServerPropertiesReader {
  private Properties properties = new Properties();
  
  public void loadConfig() throws IOException {
    properties.load(new FileInputStream("conf/server.properties"));
    
    Global.RELOAD_CONFIG_INTERVAL = Integer.parseInt(get("RELOAD_CONFIG_INTERVAL"));

    Global.TIME_OUT = Integer.parseInt(get("TIME_OUT"));
    Global.HEART_BREATH_SEQUENCE_TIME = Integer.parseInt(get("HEART_BREATH_SEQUENCE_TIME"));
    Global.DATA_UPDATE_SEQUENCE_TIME = Integer.parseInt(get("DATA_UPDATE_SEQUENCE_TIME"));
    
    Global.REQUEST_MANAGER_CORE_POLL_SIZE = Integer.parseInt(get("REQUEST_MANAGER_CORE_POLL_SIZE"));
    Global.REQUEST_MANAGER_MAX_POLL_SIZE = Integer.parseInt(get("REQUEST_MANAGER_MAX_POLL_SIZE"));
    Global.REQUEST_MANAGER_KEEP_ALIVE_TIME = Integer.parseInt(get("REQUEST_MANAGER_KEEP_ALIVE_TIME"));
  }
  
  private String get(String id) {
    String value = properties.getProperty(id);
    if (value == null) {
      throw new IllegalArgumentException("Property " + id + " is not exist or invalid. Plz check your config file");
    }
    return value;
  }
}
